<?php
$q=$_GET["q"];
$array= explode(",",$q);
$l_type=$array[0];
$School_Id=$array[1];
$Access_Type=$array[2];
$Id=$Access_Type.",".$School_Id.",School_Id";
$hint="";
include_once '../Login/databaseconnection.php';
if($l_type!="Select One"&&$School_Id!="")
{
$lab=mysql_query("SELECT COUNT(Lab_Id) AS T_Labs FROM lab WHERE Lab_Type='$l_type' AND School_Id='$School_Id'");
if($lab)
{
if($row_lab=mysql_fetch_array($lab))
{
$T_Labs=$row_lab['T_Labs'];
}
if($T_Labs=="")
{
$hint=$hint.'<font color="red">There are no labs for this school</font><br/>';
}
}
$lab1=mysql_query("SELECT * FROM lab WHERE Lab_Type='$l_type' AND School_Id='$School_Id'");
if($lab1)
{
while($row_lab=mysql_fetch_array($lab1))
{
if(empty($A_Labs))
{
$A_Labs='"'.$row_lab['Lab_Id'].'"';
}
else
{
$A_Labs=$A_Labs.',"'.$row_lab['Lab_Id'].'"';
}
}
}

$lab_net=mysql_query("SELECT DISTINCT(LAN_Supplier) FROM network WHERE School_Id='$School_Id' GROUP BY Lab_Id HAVING Lab_Id in ($A_Labs)");
if($lab_net)
{
while($row_lab_net=mysql_fetch_array($lab_net))
{
if($row_lab_net['LAN_Supplier']!="")
{
if(empty($lan_Suppliers))
{
$lan_Suppliers=$row_lab_net['LAN_Supplier'];
}
else
{
$lan_Suppliers=$lan_Suppliers.','.$row_lab_net['LAN_Supplier'];
}
}
}
}

$lab_res=mysql_query("SELECT * FROM resource_details WHERE School_Id='$School_Id' GROUP BY Lab_Id HAVING Lab_Id in ($A_Labs)");
if($lab_res)
{
while($row_lab_res=mysql_fetch_array($lab_res))
{
if($row_lab_res['Name_Of_Supplier']!="")
{
if(empty($res_Suppliers))
{
$res_Suppliers=$row_lab_res['Name_Of_Supplier']."_".$row_lab_res['Resource_Id'];
}
else
{
$res_Suppliers=$res_Suppliers.','.$row_lab_res['Name_Of_Supplier']."_".$row_lab_res['Resource_Id'];
}
}
}
}
$lab2=mysql_query("SELECT COUNT(Lab_Id) AS T_Labs FROM network WHERE Availability_Of_LAN='Yes' AND School_Id='$School_Id' GROUP BY Lab_Id HAVING Lab_Id in ($A_Labs)");
if($lab2)
{
if($row_lab2=mysql_fetch_array($lab2))
{
$Lan_Ava_Labs=$row_lab2['T_Labs'];
}
}
$lab3=mysql_query("SELECT COUNT(Lab_Id) AS T_Labs FROM network WHERE WAN_Connection_Type!='' AND School_Id='$School_Id' GROUP BY Lab_Id HAVING Lab_Id in ($A_Labs)");
if($lab3)
{
if($row_lab=mysql_fetch_array($lab3))
{
$Wan_Ava_Labs=$row_lab['T_Labs'];
}
}
if($Lan_Ava_Labs=="")
{
$Lan_Ava_Labs="0";
}
if($Wan_Ava_Labs=="")
{
$Wan_Ava_Labs="0";
}
 $hint=$hint.'<table class="imgholder">
		 <tr>
        <th>
         <label>Total number of ';
		 $hint=$hint.$l_type;
$hint=$hint.' labs:</label> 
</th>
         <td>';
if($T_Labs!="0")
{
$hint=$hint."<input type='text' name='T_Labs' value='$T_Labs' readonly='readonly' id='$Id' onmouseover='getdetails_popup(this.name,this.id)'/>";
}
else
{
$hint=$hint."<input type='text' name='T_Labs' value='$T_Labs' readonly='readonly' onmouseover='clearpopbox()'/>";
}
$hint=$hint.'</td>
         </tr>
		 <tr>
        <th>
		 <label>Number of lan available labs:</label> 
</th>
         <td>';	
if($Lan_Ava_Labs!="0")
{
$hint=$hint."<input type='text' name='Lan_Ava_Labs' value='$Lan_Ava_Labs' readonly='readonly' id='$Id' onmouseover='getdetails_popup(this.name,this.id)'/>";
}
else
{
$hint=$hint."<input type='text' name='Lan_Ava_Labs' value='$Lan_Ava_Labs' readonly='readonly' onmouseover='clearpopbox()'/>";
}       
$hint=$hint.'</td>
         </tr>
		 <tr>
        <th>
		 <label>Number of wan available labs:</label>
		 </th>
         <td>';
if($Wan_Ava_Labs!="0")
{
$hint=$hint."<input type='text' name='Wan_Ava_Labs' value='$Wan_Ava_Labs' readonly='readonly' id='$Id' onmouseover='getdetails_popup(this.name,this.id)'/>";
}
else
{
$hint=$hint."<input type='text' name='Wan_Ava_Labs' value='$Wan_Ava_Labs' readonly='readonly' onmouseover='clearpopbox()'/>";
}
$hint=$hint.'</td>
         </tr>
		  <tr>
        <th></th>
         <td></td>
         </tr>
		 <tr>
        <th height="87" colspan="2">';
		if($lan_Suppliers!="")
		{
$all_lan_suppliers=explode(",",$lan_Suppliers);
		if(count($all_lan_suppliers)>4)
{
$hint=$hint.'<div style="height:180px;overflow-Y:scroll;">';
}
		$hint=$hint.'<table height="68">
          <tr>
            <th>        
              <label>Lan supplier</label>
              </th>
            <th>        
              <label>Number of labs</label>
              </th>
            </tr>';
for($i=0;$i<count($all_lan_suppliers);$i++)
{
$Supplier=$all_lan_suppliers[$i];
$lab4=mysql_query("SELECT COUNT(Lab_Id) AS T_Labs FROM network WHERE LAN_Supplier='$Supplier' AND School_Id='$School_Id' GROUP BY Lab_Id HAVING Lab_Id in ($A_Labs)");
if($lab4)
{
if($row_lab=mysql_fetch_array($lab4))
{
$Number_Of_Labs=$row_lab['T_Labs'];
}
else
{
$Number_Of_Labs='0';
}
}

           $hint=$hint.'<tr>
            <td height="20">';
			if($Supplier=="")
			{
			$Supplier="_";
			}
			if($Number_Of_Labs=="")
			{
			$Number_Of_Labs='0';
			}
         $hint=$hint."<input type='text' name='Supplier' value='$Supplier' readonly='readonly' onmouseover='clearpopbox()'/>";
$hint=$hint.'</td>
            <td>';
if($Number_Of_Labs!="0")
{
$hint=$hint."<input type='text' name='Number_Of_Labs' value='$Number_Of_Labs' readonly='readonly' id='$Id,$i' onmouseover='getdetails_popup(this.name,this.id)'/>";
}
else
{
$hint=$hint."<input type='text' name='Number_Of_Labs' value='$Number_Of_Labs' readonly='readonly' onmouseover='clearpopbox()'/>";
}
$hint=$hint.'</td>
            </tr>';
			}
           $hint=$hint.'</table>';
if(count($all_lan_suppliers)>4)
{
$hint=$hint.'</div>';
}
		   }
        $hint=$hint.'</th>
         </tr>
		   </table>
<label>Resource supplyers details</label><br/>';
$all_res_suppliers=explode(",",$res_Suppliers);
for ($i = 0; $i <count($all_res_suppliers); $i++) {
 $temp =$all_res_suppliers[$i];
  if($temp!="")
  {
  if(empty($final_res_Suppliers))
  {
 $final_res_Suppliers=$temp;
 }
 else
 {
 $final_res_Suppliers=$final_res_Suppliers.",".$temp;
 }
  }
  $j = $i;
  for ($k = 0; $k <count($all_res_suppliers); $k++) 
  {
    if ($k != $j) {
      if ($temp == $all_res_suppliers[$k]) 
	  {
        $all_res_suppliers[$k]="";
      }
    }
  }
}

          $hint=$hint.'<div style="width:410px; overflow-X:scroll; ">
           <table><tr>
			   <th>        
			     <label>Organization</label>
			     </th>
			   <th>        
			     <label>Resource Type</label>
			     </th>
			   <th>        
			     <label>Number of equipments</label>
			     </th>
			   </tr>';
$exp_final_res_Suppliers=explode(",",$final_res_Suppliers);
for($i=0;$i<count($exp_final_res_Suppliers);$i++)
{
$Supplier_Resource=explode("_",$exp_final_res_Suppliers[$i]);
$Organization=$Supplier_Resource[0];
$Res_Id=$Supplier_Resource[1];
$res_type=mysql_query("SELECT * FROM resource WHERE Resource_Id='$Res_Id'");
if($row_res_type=mysql_fetch_array($res_type))
{
$Resource_Type=$row_res_type['Resource_Type'];
}
$lab5=mysql_query("SELECT COUNT(Lab_Id) AS T_Labs FROM resource_details WHERE Name_Of_Supplier='$Organization' AND Resource_Id='$Res_Id' AND School_Id='$School_Id' GROUP BY Lab_Id HAVING Lab_Id in ($A_Labs)");
if($lab5)
{
if($row_lab=mysql_fetch_array($lab5))
{
$Number_Of_Equipments=$row_lab['T_Labs'];
}
else
{
$Number_Of_Equipments='0';
}
}
if($Organization=="")
{
$Organization="_";
}
if($Resource_Type=="")
{
$Resource_Type="_";
}
 $hint=$hint.'<tr>
			     <td>';
         $hint=$hint."<input type='text' name='Organization' value='$Organization' size='30' readonly='readonly' onmouseover='clearpopbox()'/>";
$hint=$hint.'</td>
			     <td>';
         $hint=$hint."<input type='text' name='Resource_Type' value='$Resource_Type' size='25' readonly='readonly' onmouseover='clearpopbox()'/>";
$hint=$hint.'</td>
			     <td>';
if($Number_Of_Equipments!="0")
{
$hint=$hint."<input type='text' name='Number_Of_Equipments' value='$Number_Of_Equipments' readonly='readonly' id='$Id,$i,$final_res_Suppliers' onmouseover='getdetails_popup(this.name,this.id)'/>";
}
else
{
$hint=$hint."<input type='text' name='Number_Of_Equipments' value='$Number_Of_Equipments' size='7' readonly='readonly' onmouseover='clearpopbox()'/>";
}
$hint=$hint.'</td>
			     </tr>';
}
			  
			   $hint=$hint.'</table> </div>';
}
if($hint=="")
{
if($School_Id=="")
{
$response="<font color='red'>*Please select a school!</font>";
}
$response=$response.'<table class="imgholder">
		 <tr>
        <th>
         <label>Total number of ';
		 $response=$response.'lab type';
$response=$response.' labs:</label> 
</th>
         <td>';
         $response=$response."<input type='text' name='T_Labs' readonly='readonly'/>";    
$response=$response.'</td>
         </tr>
		 <tr>
        <th>
		 <label>Number of lan available labs:</label> 
</th>
         <td>';	
         $response=$response."<input type='text' name='Lan_Ava_Labs' readonly='readonly'/>";        
$response=$response.'</td>
         </tr>
		 <tr>
        <th>
		 <label>Number of wan available labs:</label>
		 </th>
         <td>';
		$response=$response."<input type='text' name='Wan_Ava_Labs' readonly='readonly'/>";
$response=$response.'</td>
         </tr>
		  <tr>
        <th></th>
         <td></td>
         </tr>
		 <tr>
        <th height="87" colspan="2"><table height="68">
          <tr>
            <th>        
              <label>Supplier</label>
              </th>
            <th>        
              <label>Number of labs</label>
              </th>
            </tr>
          <tr>
            <td height="20">';
         $response=$response."<input type='text' name='Supplier' readonly='readonly'/>";
$response=$response.'</td>
            <td>';
        $response=$response."<input type='text' name='Number_Of_Labs' readonly='readonly'/>";
$response=$response.'</td>
            </tr>
          </table>
        </th>
         </tr>
		     <tr>
			 <th colspan="2">
           <div style="width:410px; overflow-X:scroll; ">
           <table><tr>
			   <th>        
			     <label>Organization</label>
			     </th>
			   <th>        
			     <label>Resource Type</label>
			     </th>
			   <th>        
			     <label>Number of equipments</label>
			     </th>
			   </tr>
			   <tr>
			     <td>';
         $response=$response."<input type='text' name='Organization' size='30' readonly='readonly'/>";
$response=$response.'</td>
			     <td>';
         $response=$response."<input type='text' name='Resource_Type' size='25' readonly='readonly'/>";
$response=$response.'</td>
			     <td>';
         $response=$response."<input type='text' name='Number_Of_Equipments' size='7' readonly='readonly'/>";
		 $response=$response.'</td>
			     </tr>
			   </table> </div>';
}
else
{
$response=$hint;
}
echo $response;
?>